/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.toools.gwt.wmc.server.dao.toplink;

/**
 *
 * @author roman schoenbichler
 */
public class SimpleCUD {

    public static final <T> T create( T entity ) {
       T ret = null;
       EMFKeeper.EM.getTransaction().begin();
       try {
            EMFKeeper.EM.persist( entity );
            EMFKeeper.EM.flush();
            ret = entity;
        }catch( Exception e ) {}
        EMFKeeper.EM.getTransaction().commit();
        return ret;
    }

    public static final <T> Boolean delete( T entity ) {
        Boolean ret = false;
        EMFKeeper.EM.getTransaction().begin();
        try {
            EMFKeeper.EM.merge( entity );
            EMFKeeper.EM.remove( entity );
            EMFKeeper.EM.flush();
            ret = true;
        }catch( Exception e ) {
            e.printStackTrace();
        }
        EMFKeeper.EM.getTransaction().commit();
        return ret;
    }

    public static final <T> Boolean update( T entity ) {
        Boolean ret = false;
        EMFKeeper.EM.getTransaction().begin();
        try {
            EMFKeeper.EM.merge( entity );
            EMFKeeper.EM.flush();
            ret = true;
        }catch( Exception e ) {}
        EMFKeeper.EM.getTransaction().commit();
        return ret;
    }
}
